﻿@using System.Collections
@using BusinessLibrary
@model MMSWebsite.Models.Asset.Asset
@{
    var disable = false;
}
<table >
    @Html.HiddenFor(model=>model.Id)
    @Html.HiddenFor(model=>model.Customer.Id)
    <tr >
        <td class="tdLeft"> @Html.LabelFor(model => model.Customer)</td>
        <td class="tdRight"> @Html.EditorFor(model => model.Customer.Name)
        </td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.AssetName)</td>
        <td class="tdRight"> @Html.TextAreaFor(model => model.AssetName) 
            @Html.ValidationMessageFor(model => model.AssetName)</td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.AssetType)</td>
        <td class="tdRight"> @Html.DropDownListFor(model => model.AssetType.value, new SelectList(ViewBag.AssetTypes as IEnumerable), string.Empty)
            @Html.ValidationMessageFor(model => model.AssetType.value) </td>
    </tr>
    <tr>
        <td class="tdLeft"> @Html.LabelFor(model => model.Information)</td>
        <td class="tdRight"> @Html.TextAreaFor(model => model.Information) 
            @Html.ValidationMessageFor(model => model.Information)</td>
    </tr>
    @if (!Roles.Provider.IsUserInRole(User.Identity.Name, Constants.ADMIN_ROLE))
    {
        <tr>
            <td class="tdLeft"> @Html.LabelFor(model => model.Valuation.Value)</td>
            <td class="tdRight"> @Html.EditorFor(model => model.Valuation.Value)
                @Html.ValidationMessageFor(model => model.Valuation.Value)</td>
        </tr>
    }
    
    @if (Roles.Provider.IsUserInRole(User.Identity.Name, Constants.REVIEWER_ROLE))
    {
        if (Model.Valuation.Value != null)
        {
            <tr>
                <td class="tdLeft"> @Html.LabelFor(model => model.Loan.ValueLoan)</td>
                <td class="tdRight"> @Html.EditorFor(model => model.Loan.ValueLoan)
                    @Html.ValidationMessageFor(model => model.Loan.ValueLoan)</td>
            </tr>
            <tr>
                <td class="tdLeft"> @Html.LabelFor(model => model.Rate.ValueRate)</td>
                <td class="tdRight"> @Html.EditorFor(model => model.Rate.ValueRate)
                    @Html.ValidationMessageFor(model => model.Rate.ValueRate)</td>
            </tr>
        }
    }
    <tr>
        <td  class = "tdRight" colspan="2" style="text-align: center">
            <input type="submit" value="Save"> 
        </td>
           
    </tr>
</table>

@*use script to prevent edit column Name, type of asset (just only admin can edit them)*@
@if (Roles.Provider.IsUserInRole(User.Identity.Name, Constants.FV_ROLE)){ //if User has FV role
    <script type="text/javascript">
        Showalert("#Customer_Name");
        Showalert("#AssetName");
        Showalert("#AssetType_value");

        function Showalert(target) {
            $(target).click(function () {
                alert("You don't have permission to edit this field!");
            });
        }
    </script>
}

@if (Roles.Provider.IsUserInRole(User.Identity.Name, Constants.REVIEWER_ROLE))
{//if User has Reviewer role
    <script type="text/javascript">
        Showalert("#Customer_Name");
        Showalert("#AssetName");
        Showalert("#AssetType_value");
        Showalert("#Information");
        Showalert("#Valuation_Value");

        function Showalert(target) {
            $(target).click(function () {
                alert("You don't have permission to edit this field!");
                $(this).attr("readonly", "readonly");
            });
        }
    </script>
}


